package org.jeecg.modules.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.system.vo.SysVarModel;
import org.jeecg.modules.system.entity.SysVariable;
import org.jeecg.modules.system.mapper.SysVariableMapper;
import org.jeecg.modules.system.service.ISysVariableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 系统变量
 * @Author: jeecg-boot
 * @Date:   2021-10-12
 * @Version: V1.0
 */
@Service
public class SysVariableServiceImpl extends ServiceImpl<SysVariableMapper, SysVariable> implements ISysVariableService {

    @Autowired
    private SysVariableMapper variableMapper;
    @Override
    public SysVarModel querySysVariable(String code) {

        List<SysVarModel> varModels = variableMapper.querySysVariable(code);
        if(null != varModels && varModels.size()>0){
           return varModels.get(0);
        }
        return null;
    }

    @Override
    public void updateSysVariableVal(String code, String val) {

        LambdaQueryWrapper<SysVariable> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysVariable::getCode, code).eq(SysVariable::getDelFlag,0);
        List<SysVariable> variableList = variableMapper.selectList(queryWrapper);

        if(null != variableList && variableList.size()>0){
            SysVariable variable = variableList.get(0);
            variable.setValue(val);
            variableMapper.updateById(variable);
        }
    }

}
